#include "Logger.h"
#include <cstdarg>

/*
sourceName will be added to every message from here to identify the message.
Name of class is reccomended.

TriggerLevel should ofcourse in a complete system be controlled by config file.

*/
Logger::Logger(const std::string &sourceName )
{
  Logger::sourceName = sourceName;
  Logger::triggerLevel = XMLSettings::getInstance().getTriggerLevel();
  Logger::currentLevel = XMLSettings::getInstance().findLoggerLevel( sourceName );
}

Logger::~Logger(void)
{
}
/**
Simple string based log appender. Use stringstream to make your message and send it here.
*/
void Logger::Log(const std::string &message){
  if(currentLevel >= triggerLevel){
    LogSys::getInstance().Write(sourceName,currentLevel,message);
  }
}

/**
Varargs type log appender.
Against my better judgement, but it seems to be expected.
NOTE: Only handles messages (including inserted variable args) of length less than 1024!
*/
/*void Logger::Logf(Level level,const char* message, ...){
  if(level >= triggerLevel){
    va_list varArgs; 
    va_start(varArgs, message);
    char destBuffer[1024];
    vsprintf_s(destBuffer,1024 * sizeof(char),message,varArgs);
    LogSys::Instance().Write(sourceName,level,destBuffer);
  }
}

  Logger& Logger::operator<<(Level level){
  currentLevel=level;
  return *this;
}*/